#pragma once

#include "ui_KeyManagerWidget.h"
#include <QScopedPointer>

#include "IKeyOperationWidget.h"

class QMenuBar;
class QAction;

namespace kryptos { namespace controller {

  class Command;
}}

namespace kryptos { namespace ui {

class KeyManagerWidget : public QWidget
{
    Q_OBJECT

public:
    explicit KeyManagerWidget(QWidget *parent = 0);

    void setCreateKeyCommand(kryptos::controller::Command*);
    void setShareKeyCommand(kryptos::controller::Command*);

public slots:

signals:

private slots:
    void showKeyView();
    void showCreateKey();
    void showImportKey();
    void showCreateGroup();
    void showEditKey();
    void showShareKey();
    void showDeleteKey();
    void showEditGroup();
    void showDeleteGroup();
    void executeCommand();

private:
    template<class Type> void createWidget();
    void showGeneralMenu();
    void hideGeneralMenu();
    void hideAllMenues();

    enum MenuType { KeyView, CreateKey, Import, CreateGroup, EditKey, EditGroup, ShareKey};

    Ui::KeyManagerWidget ui;    

    QMenuBar*          m_menuBar;
    QAction*           m_goBackAction;
    QAction*           m_createKeyAction;
    QAction*           m_importKeyAction;
    QAction*           m_createGroupAction;
    QAction*           m_editKeyAction;
    QAction*           m_shareKeyAction;
    QAction*           m_deleteKeyAction;
    QAction*           m_editGroupAction;
    QAction*           m_deleteGroupAction;

    MenuType                      m_currentMenu;
    QScopedPointer<IKeyOperationWidget> m_currentWidget;

    kryptos::controller::Command*  m_createKeyCmd;
    kryptos::controller::Command*  m_shareKeyCmd;
};

}}
